<?php
/**
 * Location_model 地理位置模型
 */
class Location_model extends BS_Model
{
	/**
	 * [addLocation 添加自定义地理位置信息]
	 * @param [number] $params [受影响的行数]
	 */
	public function addLocation($params)
	{
		if(!is_array($params)) return ;
		$number = $this->checkLocation($params);

		if($number==true) return false;//重复

		return $this->db->insert('location',$params);
	}
	/**
	 * [checkLocation 检测地址位置是否存在]
	 * @param  [array] $params [地理位置名]
	 * @return [boole]         [是否存在]
	 */
	public function checkLocation($params)
	{
		$this->db->from('location');
		$this->db->where('location_name',$params['location_name']);
		$query = $this->db->get();
		if($query->row_array()){
			return true;
		}
		return null;
	}

	/**
	 * [getLocations 查出所有的地理位置信息]
	 * @return [array] [二维数组]
	 */
	public function getLocations($name)
	{
		$this->db->from('location');
		!empty($name) ? $this->db->like('location_name', $name, 'both') : '';
		$query = $this->db->get();
		if($query->num_rows() > 0)
		{
			return $query->result_array();
		}
		return array();
	}

	/**
	 * [delLocationById 删除记录]
	 * @param  [int] $locationId [id]
	 * @return [type]  [description]
	 */
	public function delLocatonById($locationId)
	{
		return $this->db->from('location')->where('id',$locationId)->delete();
	}	
}